<?php
namespace app\webadmin\model;

use think\Model;
use think\Log;
use think\Session;
use think\Cache;
class Admin extends Model{
    /**
     * 定义表
    */
    protected $table = 'my_table_admin';
    protected $resultSetType = 'collection';

    public function logincheck($username,$password){
        $where = ['admin_user_username'=>$username];
        $check = $this->where($where)->find();
        if($check){
            $check = $check->toArray();
            if(md5($password) == $check['admin_user_password']){
                Cache::set('admin_user',$username,3600);
                return ['code'=>200,'type'=>'success','msg'=>'登录成功'];
                // log::write('login error',['login code'=>5000,'username'=>$username,'password'=>$password,'logintime'=>date('Y-m-d H:i:s',time())]);
            }
            return ['code'=>500,'type'=>'error','msg'=>'密码不正确'];
        }
        // log::write('login error',['login code'=>5003,'username'=>$username,'password'=>$password,'logintime'=>date('Y-m-d H:i:s',time())]);
        return ['code'=>600,'type'=>'error','msg'=>'用户名不存在'];
    }
}